/* 
 * This program is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, or 
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License along 
 * with this program; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#include <QSettings>
#include "boardsettingsdialog.h"
#include "boardwatchparameters.h"
#include "components/chan.h"

BoardSettingsDialog::BoardSettingsDialog(Wishmaster::ChanWatcher* watcher, Wishmaster::Board* board, QWidget* parent) : QDialog(parent),
	m_watcher(watcher),
	m_board(board)
{
	m_ui.setupUi(this);

	Q_ASSERT(board);
	
	QSettings settings;
	Wishmaster::BoardWatchParameters params = watcher->boardWatchParameters(board->getParent()->getHost(), board->name());
	bool override = false;
	if(!params.chanName.isNull())
	{
		m_ui.cb_override->setChecked(true);
		m_ui.cb_indexOnly->setChecked(params.onlyIndex);
		m_ui.sb_refreshInterval->setValue(params.refreshPeriod);
		m_ui.cb_doNotRefresh->setChecked(!params.refresh);
	}
}

BoardSettingsDialog::~BoardSettingsDialog()
{
}

void BoardSettingsDialog::accept()
{
	bool override = m_ui.cb_override->isChecked();
	if(!override)
	{
		m_watcher->removeBoardWatchParameters(m_board->getParent()->getHost(), m_board->name());
		QDialog::accept();
		return;
	}

	Wishmaster::BoardWatchParameters params;
	params.chanName = m_board->getParent()->getHost();
	params.boardId = m_board->name();
	params.refresh = !m_ui.cb_doNotRefresh->isChecked();
	params.refreshPeriod = m_ui.sb_refreshInterval->value();
	params.onlyIndex = m_ui.cb_indexOnly->isChecked();

	m_watcher->setBoardWatchParameters(params);

	QDialog::accept();
}

